package com.zs.controller;

import com.zs.entity.Cplb;
import com.zs.service.CplbService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/cplb")
public class CplbController {
    @Autowired
    private CplbService cplbService;

    @RequestMapping("/toCplbList")
    public String toList(Model model) {
        List<Cplb> list = cplbService.getAll();
        model.addAttribute("list", list);
        return "cplbgl";
    }

    @RequestMapping("/addLb")
    public String addLb(Cplb lb) {
        cplbService.addCplb(lb);
        return "redirect:/cplb/toCplbList.do";
    }

    @RequestMapping("/toUpdateLb")
    public String toUpdateLb(@Param("id") int id, Model model) {
        Cplb cplb = cplbService.getLbById(id);
        model.addAttribute("cplb", cplb);
        return "cpUpdate";
    }

    @RequestMapping("/updateLb")
    public String updateLb(Cplb cplb) {
        cplbService.updateCplb(cplb);
        return "redirect:/cplb/toCplbList.do";
    }

    @RequestMapping("/delLb")

    public String delLb(int id) {
        cplbService.delCplb(id);
        return "redirect:/cplb/toCplbList.do";
    }


}
